﻿package com.dykj.platform.framework.common.paging;
import java.util.List;

import com.dykj.platform.framework.dao.hibernate.HibernateDBAccess;
import com.dykj.platform.framework.exception.DatabaseException;
public abstract class AbstractPQDAO extends HibernateDBAccess{
	/**
	 * 分页必须有的方法，一般不用改变
	 */
	private String dataAccessBindingTable;
	/**
	 * 权限拦截
	 */
	private IHQuerySupportDAO authSupport;

	public IHQuerySupportDAO getAuthSupport() {
		return authSupport;
	}

	public void setAuthSupport(IHQuerySupportDAO authSupport) {
		this.authSupport = authSupport;
	}

	public String getDataAccessBindingTable() {
		return dataAccessBindingTable;
	}

	public void setDataAccessBindingTable(String dataAccessBindingTable) {
		this.dataAccessBindingTable = dataAccessBindingTable;
	}

	public List query(Object objDTO, Page page) throws DatabaseException {
		Hquery hquery = createHQ(objDTO, page);
		hquery.setDataAccessAuth(page.getDataAccessAuth());
		hquery.setDataAccessBindingTable(dataAccessBindingTable);
		hquery = authSupport.createParaQuery(hquery);
		int totalRecordNum = this.getCount(hquery.getQueryString(), hquery.getParalist());
		page.setTotalRecordNum(totalRecordNum);
		List list = this.pageQuery(hquery.getQueryString(), hquery.getParalist(), page);
		return list;
	}
	public List queryNoPage(Object dto) throws DatabaseException{
		Page page = new Page();
		Hquery hquery = createHQ(dto, page);
		hquery.setDataAccessAuth(page.getDataAccessAuth());
		hquery.setDataAccessBindingTable(dataAccessBindingTable);
		hquery = authSupport.createParaQuery(hquery);
		List list = this.query(hquery.getQueryString(), hquery.getParalist());
		return list;
	}
	public abstract Hquery createHQ(Object objDTO,Page page)throws DatabaseException;

}
